package com.kefu.sys.vo;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.kefu.common.vo.AbstractSearchVo;
import com.kefu.sys.model.SysTenant;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;
import org.apache.commons.lang3.StringUtils;

@Data
@EqualsAndHashCode(callSuper = true)
@ToString(callSuper = true)
@ApiModel(description = "租户")
public class SysTenantSearchVo extends AbstractSearchVo {
    @ApiModelProperty("公司名称")
    private String tenantName;
    @ApiModelProperty("姓名")
    private String contactName;
    @ApiModelProperty("邮箱")
    private String contactEmail;
    @ApiModelProperty("电话")
    private String contactTel;
    @ApiModelProperty(value = "公司id")
    private String tenantId;

    @Override
    public LambdaQueryWrapper<SysTenant> lambdaQuery() {
        LambdaQueryWrapper<SysTenant> wrapper = Wrappers.lambdaQuery(SysTenant.class);
        if (StrUtil.isNotBlank(tenantId)) {
            wrapper.eq(SysTenant::getTenantId, tenantId);
        } else {
            wrapper.eq(SysTenant::getBshowFlag, 1);
        }
        wrapper.like(StrUtil.isNotBlank(tenantName), SysTenant::getTenantName, tenantName);
        wrapper.like(StrUtil.isNotBlank(contactName), SysTenant::getContactName, contactName);
        wrapper.like(StrUtil.isNotBlank(contactTel), SysTenant::getContactTel, contactTel);
        wrapper.like(StrUtil.isNotBlank(contactEmail), SysTenant::getContactEmail, contactEmail);
        wrapper.orderByDesc(SysTenant::getCreateTime);
        return wrapper;
    }
}